{extend name="common:base"/}
{block name='sidebar'}
{include file="article/sidebar" /} 
{/block}
{block name="body"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-12">
        <h2>内容</h2>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="panel blank-panel panel-heading background-fff">
                <div class="panel-options">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a data-toggle="tab" href="#tab1">基础</a>
                        </li>
                        <li class="">
                            <a data-toggle="tab" href="#tab2">内容</a>
                        </li>
                        <li class="">
                            <a data-toggle="tab" href="#tab3">附件</a>
                        </li>
                    </ul>
                </div>

                <form action="{:\\think\\Url::build('renew')}" method="post" id="signupForm" class="form-horizontal">
                    <div class="tab-content">
                        <div id="tab1" class="tab-pane active">
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">标题<span class="check-tips">(文档标题)</span></label>
                                <input id="url" class="form-control input-large" type="text" name="title" value="{$info.title|default=''}">
                            </div>

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">关键词<span class="check-tips">(关键词用英文逗号分开)</span></label>
                                <input id="url" class="form-control input-large" type="text" name="keywords" value="{$info.keywords|default=''}">
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">描述<span class="check-tips">(简介、描述、题记、导读)</span></label>
                                <textarea name="description" class="form-control input-large" rows="4">{$info.description|default=''}</textarea>
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">文章内容<span class="check-tips">(文章内容)</span></label>
                                <textarea name="content" id="editor_id" class="form-control" rows="4">{$info.content|default=''}</textarea>
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">标识<span class="check-tips">(同一根节点下标识不重复)</span></label>
                                <input id="url" class="form-control input-large" type="text" name="name" value="{$info.name|default=''}">
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">原文链接<span class="check-tips">(转载原文章的地址，可选)</span></label>
                                <input id="url" class="form-control input-large" type="text" name="original" value="{$info.original|default=''}">
                            </div>
                        </div>
                        <div id="tab2" class="tab-pane">

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">可见性<span class="check-tips"></span></label>
                                <div class="radio">
                                    <label><input type="radio" name="display"  value="0" > 不可见</label>
                                    <label><input type="radio" name="display"  value="1" > 所有人可见</label>
                                </div>
                            </div>

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">内容类型<span class="check-tips"></span></label>
                                <select class="form-control input-3x" name="type">
                                    {volist name=":\think\Config::get('document_model_type')" id="type"}
                                    <label><option value="{$key}" {eq name='info.type|default=""' value='$key'}selected{/eq}>{$type}</option></label>
                                    {/volist}
                                </select>
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">优先级<span class="check-tips">(越高排序越靠前)</span></label>
                                <input id="url" class="form-control input-small" type="text" name="level" value="{$info.level|default=''}">
                            </div>

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">推荐位<span class="check-tips">(多个推荐则将其推荐值相加)</span></label>
                                <div class="checkbox">
                                    {volist name=":\think\Config::get('document_position')" id="p"}
                                    <label><input type="checkbox" name="position[]" value="{$key}" {if condition="check_position($info['position']??0,$key)"}checked{/if} >{$p}</label>
                                    {/volist}
                                </div>
                            </div>
                            <div class="m-b-sm m-t-sm inline">
                                <label class=" control-label">封面<span class="check-tips">(0-无封面，大于0-封面图片ID，需要函数处理，可选)</span></label>
                                {include file="article:article_cover" /}
                            </div>

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">浏览量<span class="check-tips"></span></label>
                                <input id="url" class="form-control input-small" type="text" name="view" value="{$info.view|default=''}">
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">评论数<span class="check-tips"></span></label>
                                <input id="url" class="form-control input-small" type="text" name="comment" value="{$info.comment|default=''}">
                            </div>

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">收藏数<span class="check-tips"></span></label>
                                <input id="url" class="form-control input-small" type="text" name="bookmark" value="{$info.bookmark|default=''}">
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">外链<span class="check-tips">(0-非外链，大于0-外链ID,需要函数进行链接与编号的转换)</span></label>
                                <input id="url" class="form-control input-small" type="text" name="link_id" value="{$info.link_id|default=''}">
                            </div>

                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">创建时间<span class="check-tips"></span></label>
                                <input id="url" class="form-control input-4x date" type="text" name="create_time" value="{$info.create_time|default=''|time_format}">
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">截至时间<span class="check-tips">(0-永久有效)</span></label>
                                <input id="url" class="form-control input-4x time" type="text" name="deadline" value="{$info.deadline|default=0|time_format}">
                            </div>
                            <div class="m-b-sm m-t-sm">
                                <label class=" control-label">详情页显示模板<span class="check-tips">(参照display方法参数的定义)</span></label>
                                <input id="url" class="form-control input-large" type="text" name="template" value="{$info.template|default=''}">
                            </div>
                        </div>
                        <div id="tab3" class="tab-pane">
                            <div class="m-b-sm m-t-sm inline">
                                <label class=" control-label">文件<span class="check-tips">(需要函数处理，可选)</span></label>
                                {include file="article:article_file" /}
                            </div>
                        </div>
                        {assign name="action" value=":\think\Request::instance()->action()" /}
                        {assign name="open_draftbox" value=":\think\Config::get('open_draftbox')" /}
                        <div class="m-b-sm m-t-sm">
                            <button class="btn btn-w-m btn-primary" id='submit' type="submit">提交</button>
                            <button class="btn btn-w-m btn-default retreat">取消</button>
                            {if condition="$open_draftbox and (($action == 'add') or ($info.status == 3))"}
                            <button id="autoSave" class="btn btn-w-m btn-primary" formaction="{:\\think\\Url::build('article/autoSave')}" type="button">存草稿</button>
                            {/if}
                            <input type="hidden" name="id" value="{$info.id|default=''}"/>
                            <input type="hidden" name="pid" value="{$info.pid|default=''}"/>
                            <input type="hidden" name="group_id" value="{$info.group_id|default=''}"/>
                            <input type="hidden" name="category_id" value="{empty name='info.id'}{$category_id|default=''}{else /}{$info.category_id|default=''} {/empty}">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="css"}
<link href="__STATIC__/uploadify/Huploadify.css" rel="stylesheet" type="text/css">
<link href="__STATIC__/fancyBox/jquery.fancybox.css" rel="stylesheet" type="text/css">
<link href="__STATIC__/plugins/datetimepicker/datetimepicker.min.css" rel="stylesheet" type="text/css">
{/block}
{block name="script"}
<script type="text/javascript" src="__JS__/detail.js"></script>
<script type="text/javascript" src="__JS__/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="__JS__/plugins/validate/messages_zh.min.js"></script>
<script type="text/javascript" src="__STATIC__/plugins/datetimepicker/datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/uploadify/Huploadify.js"></script>
<script type="text/javascript" src="__STATIC__/fancyBox/jquery.fancybox.pack.js"></script>
<script type="text/javascript" src="__STATIC__/fancyBox/jquery.fancybox-media.js"></script>
<script type="text/javascript" src="__STATIC__/plugins/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="__STATIC__/plugins/kindeditor/zh_CN.js"></script>
<script type="text/javascript">
$(function () {
    static7.setChoose("display", "{$info.display|default=1}");
    highlight_subnav("{:\\think\\Url::build('article/index')}");
    $("#signupForm").validate({
        rules: {
            title: {
                required: true,
                minlength: 2
            },
            content: "required"
        },
        messages: {
            title: {
                required: '标题不能为空',
                minlength: '至少两个字符以上'
            },
            content: {
                required: "内容不能为空"
            }
        },
        submitHandler: function () {
            validateAjax("#signupForm", "button[type='submit']");
            return false;
        }
    });
    $.fn.datetimepicker.dates['zh-CN'] = {
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"], daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], today: "今天", suffix: [], meridiem: ["上午", "下午"]
    };
    $('.date,.time').datetimepicker({format: 'yyyy-mm-dd hh:ii:ss', language: "zh-CN", minView: 2, todayBtn: true, todayHighlight: true, autoclose: true});
    var editorContent;
    KindEditor.options.filterMode = false;
    KindEditor.ready(function (K) {
        editorContent = K.create('#editor_id', {allowFileManager: false,width: '100%',height: '600px',resizeType: 1, pasteType: 2,urlType: 'absolute',uploadJson: "{:\\think\\Url::build('Article/editorPicture')}"});
        editorContent.sync();
    });
    
    $('textarea[name="content"]').closest('form').submit(function () {
        editorContent.sync();//传统表单提交同步
    });
    $('#autoSave,#submit').on('click', function () {
        editorContent.sync();//ajax提交之前同步
    });
    
{if condition="$open_draftbox and (($action == 'add') or ($info.status == 3))"}
    //保存草稿
    var interval;
    $('#autoSave').on('click',function () {
        var target = $(this).attr('formaction');
        var form = $("#signupForm");
        var query = form.serialize();
        var that = this;
        $(that).attr('autocomplete', 'off').prop('disabled', true);
        $.post(target,query,function(data){
            if (data.code == 0) {
                alert_msg("草稿保存失败："+data.msg,0);
            } else{
                alert_msg(data.msg,1);
                $('input[name="id"]').val(data.data);
            }
            setTimeout(function () {
                $(that).prop('disabled', false);
            }, 1500);
        });
        //重新开始定时器
        clearInterval(interval);
        autoSaveDraft();
        return false;
    });
    //Ctrl+S保存草稿
    $('body').keydown(function(e){
        if(e.ctrlKey && e.which == 83){
            editorContent.sync();
            $('#autoSave').click();
            return false;
        }
    });
    //每隔一段时间保存草稿
    function autoSaveDraft(){
        interval = setInterval(function(){
            //只有基础信息填写了，才会触发
            var title = $('input[name="title"]').val();
            var name = $('input[name="name"]').val();
            var des = $('textarea[name="description"]').val();
            if(title != '' || name != '' || des != ''){
                editorContent.sync();
                $('#autoSave').click();
            }
        }, 1000*parseInt({:\\think\\Config::get('draft_aotosave_interval')}));
    }
    autoSaveDraft();
{/if}
});
</script>
{/block}